package com.squirrel.common.controller;


import com.squirrel.common.response.ResponseResult;
import com.squirrel.common.response.ResponseResultUtils;
import com.squirrel.common.response.code.CodeEnum;
import com.squirrel.common.service.ChannelService;
import com.squirrel.common.vo.channel.ChannelParentVO;
import com.squirrel.common.vo.channel.ChannelVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * ChannelController 频道控制器
 * </p>
 *
 * @author 关远键
 * @since 2021/11/11 16:06
 */
@RestController
@RequestMapping("/api/channel")
@Api(tags = "频道控制器")
public class ChannelController {

    @Autowired
    private ChannelService channelService;

    @GetMapping("/getParentList")
    @ApiOperation("顶级频道")
    public ResponseResult<List<ChannelVO>> getParentList() {
        return getListByParent(0);
    }


    @GetMapping("/getListByParent")
    @ApiOperation("子频道")
    public ResponseResult<List<ChannelVO>> getListByParent(Integer parentId) {
        List<ChannelVO> list = channelService.getChannelByParent(parentId);
        return ResponseResultUtils.success(CodeEnum.SUCCESS, list);
    }

    @GetMapping("/getList")
    @ApiOperation("级联频道")
    public ResponseResult<List<ChannelParentVO>> getList() {
        List<ChannelParentVO> list = channelService.getChannelList();
        return ResponseResultUtils.success(CodeEnum.SUCCESS, list);
    }


}
